import axios from 'axios'

const state = {
    showingUpList: [],
    upComingList: [],
}

const mutations = {
    SHOWINGUPLIST(state, payload) {
        setTimeout(() => {
            state.showingUpList = state.showingUpList.concat(payload)
        }, 300);
    },

    UPCOMINGLIST(state, payload) {
        setTimeout(() => {
            state.upComingList = payload
        }, 300);
    }
}

const actions = {
    // 正在热映
    getShowingUpList(store, payload) {
        axios({
            url: "https://m.maizuo.com/gateway?cityId=310100&pageNum="+payload.pageNum+"&pageSize=10&type=1",
            headers: {
                "X-Client-Info": '{"a":"3000","ch":"1002","v":"5.0.4","e":"1583716737571230650801","bc":"310100"}',
                "X-Host": "mall.film-ticket.film.list"
            }
        }).then(res => {
            if(res.data.msg === "ok") {

                store.commit("SHOWINGUPLIST", res.data.data.films)
            }
        })
    },

    // 即将上映
    getUpComingList(store) {
        axios({
            url: "https://m.maizuo.com/gateway?cityId=440100&pageNum=1&pageSize=10&type=2",
            headers: {
                "X-Client-Info": '{"a":"3000","ch":"1002","v":"5.0.4","e":"1583716737571230650801","bc":"440100"}',
                "X-Host": 'mall.film-ticket.film.list'
            }
        }).then(res => {
            store.commit("UPCOMINGLIST", res.data.data.films)
        })
    }
}


export default {
    namespaced: true,
    state,
    mutations,
    actions
}
